<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
    
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input class="layui-input" placeholder="开始日" name="start" id="start"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input class="layui-input" placeholder="截止日" name="end" id="end"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="contrller">
                                        <option>支付方式</option>
                                        <option>支付宝</option>
                                        <option>微信</option>
                                        <option>货到付款</option></select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="contrller">
                                        <option value="">订单状态</option>
                                        <option value="0">待确认</option>
                                        <option value="1">已确认</option>
                                        <option value="2">已收货</option>
                                        <option value="3">已取消</option>
                                        <option value="4">已完成</option>
                                        <option value="5">已作废</option></select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="order_no" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="search">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()">
                                <i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('添加订单','./order_add.html',800,600)">
                                <i class="layui-icon"></i>添加</button></div>
                        <table class="layui-hide" id="test" lay-filter="demo"></table>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script>
        layui.use(['table', 'form'], function () {
            var table = layui.table;
            var form = layui.form;
            table.render({
                elem: '#test'
                , url: '/index.php/admin/order/list1'
                , page: true
                , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                , cols: [[
                    {type: 'checkbox'}
                    , {field: 'order_no', width: 100, title: '订单编号', sort: true}
                    , {field: 'user_id', width: 100, title: '用户ID',sort: true}
                    , {field: 'pro_title', width: 100, title: '商品'}
                    , {field: 'total', width: 100, title: '商品金额'}
                    , {field: 'total_pay', width: 180, title: '总金额'}
                    , {field: 'order_status', width: 180, title: '订单状态'}
                    , {field: 'pay_status', width: 180, title: '支付状态'}
                    , {field: 'ship_status', width: 180, title: '物流状态'}
                    , {field: 'payment', width: 180, title: '支付方式'}
                    , {
                        field: 'add_time',
                        width: 180,
                        title: '下单时间',
                        templet: "<div>{{layui.util.toDateString(d.add_time, 'yyyy-MM-dd HH:mm:ss')}}</div>"
                    }
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 250}
                ]],

                done: function(res, curr, count){

                    $(".layui-table-box").find("[data-field='id']").css("display","none");

                    $("[data-field='pay_status']").children().each(function(){
                        if($(this).text()=='1'){
                            $(this).text("已支付")
                        }else if($(this).text()=='0'){
                            $(this).text("未支付")
                        }
                    });
                    $("[data-field='order_status']").children().each(function(){
                        if($(this).text()=='1'){
                            $(this).text("已锁定")
                        }else if($(this).text()=='0'){
                            $(this).text("未锁定")
                        }
                    });
                    $("[data-field='ship_status']").children().each(function(){
                        if($(this).text()=='1'){
                            $(this).text("已发货")
                        }else if($(this).text()=='0'){
                            $(this).text("未发货")
                        }
                    });
                    pageCurr=curr;
                }
            });
            form.on('submit(search)', function (data) {

                var order_no = data.field.order_no;
                console.log(order_no);
                table.reload('test', {
                    url: "{:url('admin/order/order_like')}"
                    , request: {}
                    , where: {
                        order_no: order_no
                    }
                });
                return false;   //表单按钮的js回调函数添加retrun false制止
            });

            table.on('checkbox(demo)', function (obj) {
                console.log(obj)
            });
            //监听工具条
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    layer.msg('ID：' + data.id + ' 的查看操作');
                }else if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: 'get',
                            url: "{:url('admin/order/order_delete')}",
                            data: {id: data.id},
                        });
                        obj.del();
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {

                    // layer.alert('编辑行：<br>'+ JSON.stringify(data))
                    layer.open({
                        title: ['修改数据', 'font-size:18px;'],
                        type: 2,
                        area: ['600px', '400px'], //宽高
                        content: '/index.php/admin/order/order_edit',
                        scrollbar: false,
                        success: function (layero, index) {

                            var inp = $(layero).find("iframe").contents().find("#id");
                            inp.val(data.id);

                        }
                    });
                }
            });

            var $ = layui.$, active = {
                getCheckData: function () { //获取选中数据
                    var checkStatus = table.checkStatus('idTest')
                        , data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
                , getCheckLength: function () { //获取选中数目
                    var checkStatus = table.checkStatus('idTest')
                        , data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                }
                , isAll: function () { //验证是否全选
                    var checkStatus = table.checkStatus('idTest');
                    layer.msg(checkStatus.isAll ? '全选' : '未全选')
                }
            };

            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
    <script>
        function delAll(argument) {

            var data = tableCheck.getData();

            layer.confirm('确认要删除吗？' + data,
            function(index) {
                //捉到所有被选中的，发异步进行删除
                layer.msg('删除成功', {
                    icon: 1
                });
                $(".layui-form-checked").not('.header').parents('tr').remove();
            });
        }
    </script>

</html>